package com.lych.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lych.dubbo.mappers.UserMapper;
import com.lych.model.domain.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;

    @Override
    //根据手机号查询用户
    public User findByMobile(String mobile) {
        LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
        lqw.eq(User::getMobile,mobile);
        return userMapper.selectOne(lqw);
    }

    /**
     * 首次登录---完善资料
     * @param user
     * @return
     */
    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    /**
     * 修改手机号 - 3 保存
     * @param user
     */
    @Override
    public void updatePhone(User user) {
        LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
        lqw.eq(User::getId,user.getId());
        userMapper.update(user,lqw);
    }

    /**
     * 设置环信的信息
     * @param user
     */
    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    /**
     * 通过userid查询信息
     * @return
     */
    @Override
    public User findById(Long userId) {
        User user = userMapper.selectById(userId);
        return user;
    }

    /**
     * 根据huanxinId查询user用户信息
     * @return
     */
    @Override
    public User findByHuanXinId(String huanxinId) {
        LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
        lqw.eq(User::getHxUser,huanxinId);
        return userMapper.selectOne(lqw);
    }
}
